import koa from 'koa'
const app = new koa()
import bodyParser from 'koa-bodyparser'
import path from 'path'
import koaStatic from 'koa-static'
import userRouter from './routes/user'
import slideRouter from './routes/slide'
import uploadRouter from './routes/upload'
import commentRouter from './routes/comment'
import musicRouter from './routes/music'
import connection from './config/mysqlConfig'
import appConfig from './config/appConfig'
import  { myJwt } from './middleware/myJwt'
connection.connect()

// 静态资源配置
app.use(koaStatic(path.join(__dirname, './uploads')))
app.use(bodyParser())

// token校验
app.use(myJwt)

// 用户相关路由
app.use(userRouter.routes())
app.use(userRouter.allowedMethods())

// 轮播图相关路由
app.use(slideRouter.routes())
app.use(slideRouter.allowedMethods())

// 文件上传
app.use(uploadRouter.routes())
app.use(uploadRouter.allowedMethods())

// 评论相关
app.use(commentRouter.routes())
app.use(commentRouter.allowedMethods())

// 音乐相关
app.use(musicRouter.routes())
app.use(musicRouter.allowedMethods())

app.listen(appConfig.port, () => {
    console.log(`服务器已启动在${appConfig.port}端口`)
})
